var models = require('../models/recommend.js').recommend;
var moment = require('moment');
var ObjectId = require('mongoose').Types.ObjectId;
var menus = require('./menu').menu();
menus.recommend.active = 'active';
module.exports.autoroute = {
	get:{
		'/admin/recommend':function(req,res){
			res.render("recommend",{menu:menus})
		},
		'/admin/ajax/recommend':function(req,res){
			var page = 1;
			if(req.query.page)
				page = req.query.page;
			condition = {};
			if(req.query.username)
				condition.username = new RegExp(req.query.username);
			models.find(condition).skip((page-1)*10).limit(10).lean(true).exec(function(err,user){
				models.find().count(function(err,size){
					user.forEach(function(item){
						item.create_time = moment(item.create_time).format("YYYY-MM-DD HH:mm");
					});
		  			res.json({aaData:user,iTotalRecords:size,iTotalDisplayRecords:size});
				})
			});
		},
	}
};